package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.AreaService;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class AreaController {
    @Autowired
    private AreaService areaService;

    //查询当前行政区域数据 省的列表
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> provinceList(){
        //考虑 下一个接口 传递parentId 查询列表功能
        //做一个业务层方法的复用 接收parentId 查询下级list
        Integer parentId=0;
        return new Result<>(areaService.getAreaList(parentId));
    }
    //根据所选的省或者市id查询下级列表
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> childrenList(@PathVariable("parentId") Integer parentId){
        return new Result<>(areaService.getAreaList(parentId));
    }
    //查询全量数据area,封装成三级的结构
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree(){
        return new Result<>(areaService.tree());
    }

}
